<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.8/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<div class="layui-btn-container">
    <button type="button" class="layui-btn layui-btn-primary" lay-on="alert" onclick="onAlert()">Alert</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="confirm" onclick="onConfirm()">Confirm</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="msg">Msg</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="page">Page</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="iframe">Iframe</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="load">Load</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="tips">Tips</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="prompt">Prompt</button>
    <button type="button" class="layui-btn layui-btn-primary" lay-on="photots">Photots</button>
</div>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="//unpkg.com/layui@2.9.8/dist/layui.js"></script>
<script>
    // $('button[lay-on="alert]')
    function onAlert() {
        layer.alert('这是一个警告1', {icon: 2});
    }

    function onConfirm() {
        //var index = layer.confirm(
        layer.confirm(
            '一个confirm框1',
            {icon: 3},
            function (index) {
                console.log('点击确认');
                layer.close(index);
                //layer.msg('点击确认', {icon: 1});
            },
            function () {
                //layer.msg('点击取消', {icon: 2});
                layer.msg('点击取消', {time: 2000, btn: ['明白了', '知道了']});
            }
        );
    }

    /*layui.use(function () {
        var layer = layui.layer;
        var util = layui.util;
        util.on('lay-on', {
            alert: function() {
                layer.alert('这是一个警告');
            },
            confirm: function (){
                layer.confirm(
                    '一个confirm框',
                    {btn: ['确认', '关闭']},
                    function () {
                        layer.msg('点击确认', {icon: 1});
                    },
                    function () {
                        //layer.msg('点击取消', {icon: 2});
                        layer.msg('点击取消', {time: 2000, btn: ['明白了', '知道了']});
                    }
                );
            }
        })
    });*/

</script>

</body>
</html>